$(function () {
    $('.btn-save').on('click',function () {
        var mobile = $('.mobile').val(),
            cost = $('.cost').val();
        $('.btn-save').attr('disabled');
        if (!mobile){
            lightyear.notify('手机号不能为空~', 'danger', 5000, 'mdi mdi-emoticon-neutral', 'top', 'center');
            return false;
        }
        if (cost == ''){
            lightyear.notify('金额不能为空~', 'danger', 5000, 'mdi mdi-emoticon-neutral', 'top', 'center');
            return false;
        }
        //获取用户名
        var param = {};
        var base = new Base64();
        param.action = base.encode('name');
        param.mobile = base.encode(mobile);
        param.cost = base.encode(cost);
        $.post('cost',param,function (result) {
            if (!result.status){
                lightyear.notify(result.msg, 'danger', 1000, 'mdi mdi-emoticon-neutral', 'top', 'center');
                return false;
            }
            var param = {};
            param.mobile = base.encode(mobile);
            param.cost = base.encode(cost);
            param.action = base.encode('cost');
            $.alert({
                title: '请认真核对后再进行操作',
                content: '手机号：<strong>'+mobile+'</strong><br>用户姓名：<strong>'+result.data.name+'</strong><br>充值金额：<strong>'+cost+'</strong><br>当前用户金额：<strong>'+result.data.total_cost+'</strong><br>充值后金额：<strong>'+(result.data.result_cost)+'</strong>',
                buttons: {
                    confirm: {
                        text: '确认',
                        btnClass: 'btn-primary',
                        action: function(){
                            $.post('cost',param,function (res) {
                                if (res.status){
                                    lightyear.notify(res.msg, 'info', 1000, 'mdi mdi-emoticon-happy', 'top', 'center', 'users.html');
                                } else {
                                    lightyear.notify(res.msg, 'danger', 1000, 'mdi mdi-emoticon-neutral', 'top', 'center');
                                }
                            },'json');
                        }
                    },
                    cancel: {
                        text: '取消',
                        action: function () {

                        }
                    }
                }
            });


        },'json');
    });
});